﻿Imports System.Xml
Public Class Authentication
    Private applicationKey As String
    Public sessionID As String


    Sub New(ByVal appKey As String)
        applicationKey = appKey
    End Sub

    Function performLogin(ByVal username As String, ByVal password As String) As Boolean
        Dim oComm As New Communication
        Dim oParamBuilder As New ParamBuilder
        Dim blnLoggedIn As Boolean = False

        oParamBuilder.addParam("apiKey", applicationKey)
        oParamBuilder.addParam("l", username)
        oParamBuilder.addParam("password", password)

        Dim sXml As String

        sXml = oComm.getResponseFromOrb(Communication.APILogonURI, oParamBuilder.GetParamList)

        Dim oXmlReader As XmlNodeReader = oComm.ConvertStringToXmlReader(sXml)

        While oXmlReader.Read
            Select Case oXmlReader.NodeType
                Case XmlNodeType.Element
                    If oXmlReader.Name = "status" Then
                        If oXmlReader.GetAttribute("code") = "0" Then
                            blnLoggedIn = True
                        End If
                    End If

                    If oXmlReader.Name = "response" Then
                        'niets
                    End If

                    If oXmlReader.Name = "orbSession" Then
                        'yes - we hemmen hem ;)

                    End If

                    If oXmlReader.Name = "orbSessionId" Then
                        sessionID = oXmlReader.ReadElementContentAsString

                    End If

                Case Else

            End Select

        End While
        Return blnLoggedIn

    End Function
End Class
